<template>
  <view>
    <view class="input-search">
		<scanCode :scanType="3"></scanCode>
    	<uni-easyinput prefixIcon="search"  trim="all" v-model="keyword" :styles="styles" :placeholderStyle="placeholderStyle"></uni-easyinput>
    	<button @click="search">搜索</button>
    </view>
    <uni-table ref="table" type="selection" stripe :loading="loading" border emptyText="暂无更多数据" filter-type="search" @selection-change="selectionChange">
		<uni-tr>
			<uni-th>
				<button class="close_btn" @click="toCheck">{{pass_status==0?'审核通过':'确认移库'}}</button>
			</uni-th>
		</uni-tr>
		<uni-tr v-for="(item, index) in card_arr" :key="index" >
			<uni-td width="100%" align="left" class="td-class" >
				<div class="td_div">
					<view class="td_list">
						<text class="label">订单编号：</text>
						<text class="text">{{ item.source_code }}</text>
					</view>
					<view class="td_list">
						<text class="label">PDA单号：</text>
						<text class="text">{{ item.pcode }}</text>
					</view>
					<view class="td_list">
						<text class="label">单据日期：</text>
						<text class="text font-red">{{ item.pdate }}</text>
					</view>
					<view class="td_list">
						<text class="label">名称：</text>
						<text class="text">{{ item.inv_name }}</text>
					</view>
					<view class="td_list">
						<text class="label">编码：</text>
						<text class="text">{{ item.inv_number }}</text>
					</view>
					<view class="td_list">
						<text class="label">规格：</text>
						<text class="text">{{ item.inv_specification }}</text>
					</view>
					<view class="td_list">
						<text class="label">单位：</text>
						<text class="text">{{ item.unit_name }}</text> 
					</view>
					<view class="td_list">
						<text class="label">批号：</text>
						<text class="text">{{ item.cBatch }}</text> 
					</view>
					<view class="td_list">
						<text class="label">数量：</text><text class="text">{{ item.quantity }}</text>
					</view>
					<view class="td_list">
						<text class="label">仓库：</text>
						<text class="text font-red">{{ item.warehouse_name }}</text>
					</view>
					<view class="td_list">
						<text class="label">库区：</text>
						<text class="text font-red">{{ item.shelves_name }}</text>
					</view>
					<view class="td_list">
						<text class="label">备注：</text>
						<text class="text">{{ item.remark }}</text>
					</view>
					<!-- <view class="td_list">
						<text class="label">状态：</text>
						<text class="text font-red" v-show="item.pass_status==0">待质检</text>
						<text class="text" v-show="item.pass_status==1">已质检</text>
					</view> -->
				</div>
			</uni-td>
        </uni-tr>
    </uni-table>
    <view class="uni-pagination-box">
		<uni-pagination show-icon :page-size="pageSize" :current="currentPage"
        :total="total" @change="change" />
	</view>
  </view>
</template>

<script>
// 引入uni-ui组件
import scanCode from '@/component/scan-code.vue'
import {
  uniPagination,
  uniIcons,
  uniCard,
  uniTable,
  uniTr,
  uniTh,
  uniTd,
  uniEasyinput,
  uniPopup,uniDataCheckbox
} from "@dcloudio/uni-ui"
//import baTreePicker from "@/components/ba-tree-picker/ba-tree-picker.vue"
export default {
  data() {
    return {
      card_arr: [],//当前页码的表格数据
      pageSize: 15,// 每页数据量
      currentPage: 1,// 当前页
      total: 0,// 数据总量
      loading: false,
      selectedIndexs:[],//选中: '',
      
	  placeholderStyle:'font-size:17px;',
	  styles:{
	  	borderColor: '#999'
	  },
	  
	  keyword:'',
	  where:' 1=1 ',
	  order_list:1,
	 //  order_list:'1,14',
	 //  order_list_arr: [
		//   {
		// 	text: '全部',
		// 	value: '1,14'
		//   },
		// {
		// 	text: '外购入库',
		// 	value: 1
		// },{
		// 	text: '产品入库',
		// 	value: 14
	 //  }],
	  pass_status:0,
	  user:uni.getStorageSync('user'),
	  //在线版
	  config:uni.getStorageSync('myconfig'),
	  pageinfo:{},
	  //
    }
  },
  components: {
    uniPagination,
    uniIcons, //uni-ui的icons组件
    uniCard, //uni-ui的卡片组件
    uniTable,
    uniTr,
    uniTh,
    uniTd,
	uniEasyinput,scanCode,uniPopup,uniDataCheckbox
  },
  onPullDownRefresh() {
  	this.getlist()
	uni.stopPullDownRefresh();
  },
  onNavigationBarButtonTap(e) {
	if(e.type=='menu'){
		//弹窗
		this.$refs.popup.open()
	}
  },
  methods: {
    // 点击关闭的事件回调
    close() {
      uni.navigateBack({})
    },
	// 搜索
	search() {
		this.currentPage = 1
		this.getlist();
	},
    //获取列表
    getlist() {
		uni.showLoading();
		if(!this.config.online){
			/* this.where = ' 1=1 '
			
			this.$Db.queryCount('procure',this.where).then(res => {
				this.total = res[0].num;//获得总页数
			})
			this.$Db.queryDataList('procure',this.currentPage,this.pageSize,this.where,'pcode','desc').then(res => {
				this.card_arr = []
				res.forEach((item,index)=>{
					item.rat = parseInt(item.commit_quantity*100/item.quantity)
					this.card_arr.push(item)
				})
				uni.hideLoading();
			}) */
			this.$Api.msg('暂无数据');
		}else{
			//20231204在线版
			let condition = {
				 keyword:this.keyword,
				 order_list:this.order_list,
				 pass_status:this.pass_status,
				 warehouse_id:this.user.stock_id
			}
			
			this.pageinfo = {
				table:'incheck',
				pagesize:this.pageSize,
				page:this.currentPage,
				order_str:'pass_status asc',
				condition_str:JSON.stringify(condition)
			}
			
			this.$Api.getPageList(this.pageinfo).then(res=>{
				this.card_arr = res.data.data;
				this.total = res.data.total
				this.currentPage = res.data.current_page
				uni.hideLoading();
			}).catch(err=>{
				this.$Api.msg(err)
			})
			//
		}
    },
	closePup(){
		this.$refs.popup.close()
		this.getlist();
	},
    change(e) {
      this.currentPage = e.current
      this.getlist()
    },
	// 多选
	selectionChange(e) {
		this.selectedIndexs = e.detail.index
	},
	//审核通过
	toCheck(){
		let _this = this;
		let pcode_arr = []
		
		uni.showModal({
		    title: '确定要'+(this.pass_status==0?'质检审核通过?':'进行移库?'),
		    //content: '确定要删除记录？',
		    success: function (res) {
		        if (res.confirm) {
					if(_this.selectedIndexs.length>0){
						_this.selectedIndexs.forEach(key=>{
							let pcode = _this.card_arr[key].pcode
							if(pcode_arr.indexOf(pcode)=== -1){
							    pcode_arr.push(pcode)
							}
						})
						uni.showLoading();
						_this.$Api.addDbIncheckOrder(pcode_arr,_this.user.userid,_this.pass_status,'wg').then(res=>{
							uni.hideLoading();
							_this.$refs.table.clearSelection()
							if(res.data.code){
								_this.$Api.msg('操作成功','success')
								setTimeout(function() {
									_this.getlist()
								}, 800);
							}else{
								_this.$Api.msg(res.data.msg)
							}
						})
						
					}
		        }
		    }
		});
	}
  },
  mounted(e) {},
  onLoad(e) {
	//更新标题
	this.pass_status = e.pass_status
	if(e.pass_status==0){
		this.$Func.setBarTitle('外购入库质检列表')
	}else{
		this.$Func.setBarTitle('入库移库列表')
	}
	this.getlist()
	/* 监听传过来的扫描单号 */
	uni.$on("scan_erp_order", (value) => {
		let arr = value.split('!');
		if(arr.length>1){
			this.keyword = arr[0].substr(2)
		}else{
			this.keyword = value;
		}
		this.search()
	})
  },
  destroyed() {
  	uni.$off("scan_erp_order")
	this.globalData.toSecPage = ''
  }
}
</script>
<style lang="less">
	.popup-content{
		height: 300rpx;
		padding-bottom:100rpx;
	}
</style>